package com.yuanchu.search.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.search.dto.OrderDetailDto;
import com.yuanchu.search.dto.QueryOrderParamsDto;
import com.yuanchu.search.dto.TradeTrendVO;
import com.yuanchu.search.dto.UserOrderCountsDto;
import com.yuanchu.search.service.OrderService;
import com.yuanchu.search.utils.SecurityUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-29 13:04
 */
@RestController
@RequestMapping("order")
public class OrderSearchController {

    @Resource
    private OrderService orderService;


    Integer storeId = 10001;

    @ApiOperation(value = "/order/list&dataType=all&page=1", tags = "查询商家订单列表")
    @GetMapping("/store/list")
    public R geStoreOrderList(QueryOrderParamsDto param) {
        // 根据dataType和page获取用戶订单列表数据
        PageResult<OrderDetailDto> orderList = orderService.queryStoreOrderList(param);

        Map<String, Object> map = new HashMap<>();
        map.put("list", orderList);
        return R.ok().put("data", map);
    }

    @ApiOperation(value = "/store/order/detail&orderId=3", tags = "根据订单id 查询商家订单详情")
    @GetMapping("/store/detail")
    public R getStoreOrderDetail(@RequestParam Integer orderId) {
        OrderDetailDto orderDetail = orderService.getStoreOrderDetail(orderId, storeId);
        Map<String, Object> detail = new HashMap<>();
        detail.put("detail", orderDetail);
        return R.ok().put("data", detail);
    }

    @ApiOperation(value = "/order/detail&orderId=3", tags = "根据订单id 查询用户订单详情")
    @GetMapping("/order/detail")
    public R getOrderDetail(@RequestParam Integer orderId) {
        Integer userId = SecurityUtil.getUserId();
        OrderDetailDto orderDetail = orderService.getOrderDetailByOrderId(orderId, userId);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("order", orderDetail);
        Map<String, Object> setting = new HashMap<>();
        setting.put("points_name", "积分");
        resultMap.put("setting", setting);
        return R.ok().put("data", resultMap);
    }

    @ApiOperation(value = "/order/list&dataType=all&page=1", tags = "查询用户订单列表")
    @GetMapping("/order/list")
    public R getOrderList(@RequestParam String dataType, @RequestParam Integer page) {
        // 根据dataType和page获取用戶订单列表数据
        Integer userId = SecurityUtil.getUserId();
        PageResult<OrderDetailDto> orderList = orderService.queryOrderList(dataType, page, userId);
        Map<String, Object> map = new HashMap<>();
        map.put("list", orderList);
        return R.ok().put("data", map);
    }


    @ApiOperation(value = "/order/todoCounts", tags = "查询统计处理订单数")
    @GetMapping("/order/todoCounts")
    public R queryOrderCounts() {
        Integer userId = SecurityUtil.getUserId();
        UserOrderCountsDto userOrderCounts = orderService.queryOrderCounts(userId);
        Map<String, Object> map = new HashMap<>();
        map.put("counts", userOrderCounts);
        return R.ok().put("data", map);
    }

    @ApiOperation(value = "/order/trend", tags = "查询订单趋势")
    @GetMapping("/order/count/trend")
    public TradeTrendVO getTradeTrend() {
        return orderService.getTradeTrend();
    }

    @ApiOperation(value = "/order/count/pending", tags = "统计订单数")
    @GetMapping("/order/count/pending")
    public Map<String, String> queryPending() {
        return orderService.queryPending();
    }

    @ApiOperation(value = "/order/count/pending", tags = "消费情况")
    @GetMapping("/order/count/statistic")
    public Map<String, String> queryConsumption() {
        return orderService.queryConsumption();
    }

    @ApiOperation(value = "/order/sales/overview", tags = "查询当日订单销量实时概况")
    @GetMapping("/order/sales/overview")
    public Map<String, Object> queryOverview() {
        return orderService.queryOverview();
    }

    @ApiOperation(value = "/order/sales/month", tags = "查询当月订单销量实时概况")
    @GetMapping("/order/sales/month")
    public List<OrderDetailDto> queryOrderSalesByMonth() {
        return orderService.queryOrderSalesByMonth();
    }

    @GetMapping("/order/sales")
    public List<Map<String, Object>> queryOrderSales() {
        return orderService.queryOrderSales();
    }
    @ApiOperation(value = "/order/sales/month", tags = "查询订单销量概况")
    @GetMapping("/order/sales/all")
    public List<OrderDetailDto> queryOrderSalesAll() {
        return orderService.queryOrderSalesAll();
    }
    @GetMapping("/order/pay/count")
    public Map<String, String> queryPayOrderCount(){
        return orderService.queryPayOrderCount();
    }
}
